package sg.edu.nus.iss.team2s.jass.io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import sg.edu.nus.iss.team2s.jass.dto.JobSeeker;

/**
 * IO data access implementation for JobSeeker
 * @author Zheng Xiaofeng
 * @version 1.0
 */

public class JobSeekerAccessImpl implements DataAccessI {
	/*
	 * the constructor args are harded-code here, java reflection api can be
	 * used here to map the properties file fields to java attributes
	 * @see sg.edu.nus.iss.team2s.jass.io.DataAccessI#parseObjectsFromReader(java.io.BufferedReader)
	 */
	@Override
	public List<Object> parseObjectsFromReader(BufferedReader in)
			throws IOException {
		List<Object> objList = new ArrayList<Object>();
		String lineStr;
		int lineCount = 0;
		JobSeeker jobSeeker = null;
		String[] str = new String[10];
		while((lineStr = in.readLine()) != null){
			str[lineCount] = lineStr.substring(lineStr.indexOf("=")+1,lineStr.length());
			lineCount++;
			if(lineCount == str.length){
				jobSeeker = new JobSeeker(str[0],str[1],str[2], str[3],str[4],str[5], str[6],str[7],str[8], str[9]);
				objList.add(jobSeeker);
				lineCount = 0;
			}
		}
		return objList;
	}

	@Override
	public void writeObjectsToWriter(List<Object> objects, BufferedWriter out)
			throws IOException {
		/*
		 * This is method is left unimplemented as the maintenance of job seekers is out of
		 * scope. 
		 */
		throw new IOException("IO Data access for job seekers is not supported in this version!");

	}

}
